package com.intelligent.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.pojo.ReceiptWriteOff;
import com.intelligent.service.ReceiptWriteOffService;
import com.intelligent.utils.Result;
import com.intelligent.vo.ReceiptWriteOffPageReq;
import com.intelligent.vo.ReceiptWriteOffResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/receipt-write-off")
public class ReceiptWriteOffController {

    @Autowired
    private ReceiptWriteOffService service;

    @PostMapping("/page")
    public Result<Page<ReceiptWriteOffResp>> page(@RequestBody ReceiptWriteOffPageReq req) {
        return Result.success(service.page(req));
    }

    @GetMapping("/{id}")
    public Result<ReceiptWriteOffResp> detail(@PathVariable Long id) {
        ReceiptWriteOffResp r = service.detail(id);
        return r == null ? Result.error("未找到记录") : Result.success(r);
    }

    @PostMapping("/create")
    public Result<?> create(@RequestBody ReceiptWriteOff writeOff) {
        return service.create(writeOff) ? Result.success(writeOff) : Result.error("保存失败");
    }
}
